<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class Index extends Common
{
    public function _initialize(){
        parent::_initialize();
    }
    
    public function prisoners(){
        $id = input('id');
        $data = Db('prisoners')->find($id);
        $this->assign('data',$data);
        return $this->fetch();
    }
    

    public function prison(){
        $id = input('id');
        $prison = Db('prison')->where('id',$id)->find();
        $data = Db('bed')->where('pid',$id)->select();
        foreach ($data as $key => $val) {
            $user = Db('prisoners')->find($val['pider_id']);
            $data[$key]['name'] = $user['name'];
            $data[$key]['uid'] = $user['id'];
        }
        $this->assign('data',$data);
        $this->assign('prison',$prison);
        return $this->fetch();
    }

    public function bed(){
        $id = input('id');
        $data = Db('bed')->where('id',$id)->find();
        $user = Db('prisoners')->find($val['pider_id']);
        $data['prison'] = Db('prison')->where('id',$data['pid'])->value('name');

        $data['name'] = $user['name'];
        $data['uid'] = $user['id'];
        $data['avatar'] = $user['avatar'];

        $this->assign('data',$data);
        return $this->fetch();
    }

    public function arctype(){
      $id = input('id'); 
      $arctype = Db('arctype')->where('id',$id)->find();
      if ($arctype['pid']!=0) {
          die;
      }
      $data = Db('arctype')->where('pid',$id)->select();
      $this->assign('arctype',$arctype);
      $this->assign('data',$data);
      return $this->fetch();
    }

    public function archive(){
      $id = input('id'); 
      $arctype = Db('arctype')->where('id',$id)->find();
      $data = Db('archive')->where('typeid',$id)->select();
      $this->assign('arctype',$arctype);
      $this->assign('data',$data);
      return $this->fetch();
    }

}
